package com.gcsoftware.web.mapper.db;

import com.gcsoftware.beans.LoginGroup;
import com.gcsoftware.beans.SysLog;
import com.gcsoftware.beans.SysUser;
import com.gcsoftware.web.mapper.AutoSql;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;
import org.mapstruct.Mapper;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

/**
 * 登陆
 * @author czp
 * date 2018-06-20
 */
@Mapper
public interface LoginMapper {
    @Select("SELECT * FROM T_DEMO_SYS_USER")
    SysUser querySysUser();

    @Insert("INSERT INTO T_DEMO_SYS_LOG\n" +
            "(\n" +
            "  C_STAFF_NAME,\n" +
            "  C_LOGIN_IP,\n" +
            "  C_BROWSER_TYPE,\n" +
            "  C_STATE\n" +
            ") VALUES (\n" +
            "  #{c_staff_name},\n" +
            "  #{c_login_ip},\n" +
            "  #{c_browser_type},\n" +
            "  #{c_state}\n" +
            ")")
    int recordLog(SysLog sysLog);

    @Select("SELECT COUNT(*) FROM T_DEMO_TENANT_INFO")
    int isInitSys();

    @Select("SELECT C_STATE, COUNT(C_STATE) AS NUM FROM T_DEMO_SYS_LOG GROUP BY C_STATE")
    List<LoginGroup> userLoginGroup();

    @Select("SELECT C_PWD_QUESTION FROM T_DEMO_SYS_USER")
    String getPwdQuestion();

    @Select("SELECT C_PWD_ANSWER FROM T_DEMO_SYS_USER")
    String getPwdAnswer();

    @Select("SELECT C_USER_NAME FROM T_DEMO_SYS_USER")
    String getUserName();

    @UpdateProvider(type = AutoSql.class, method = "updateUserInfo")
    int updateUserInfo(@ModelAttribute SysUser sysUser);

    @Select("SELECT * FROM T_DEMO_SYS_LOG")
    List<SysLog> getSysLogs();
}
